package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import model.*;
import util.ConnectDataBase;

public class EmployeeDAO {
	Vector listemployee;
	ConnectDataBase connectDataBase;
	public EmployeeDAO() {
		listemployee= new Vector();
		connectDataBase= new ConnectDataBase();
	}

	public Vector getListemployee() {
		try {
			
			ResultSet rs = connectDataBase
					.query_select("Select * from Employee");

			while (rs.next()) {
				int employee_id = Integer.parseInt(rs.getString("employee_id"));
				String firstname = rs.getString("firstname");
				String lasttname = rs.getString("lastname");
				String username = rs.getString("username");
				String password = rs.getString("password");
				int position = Integer.parseInt(rs.getString("position"));

				Employee ee = new Employee(employee_id, firstname, lasttname,
						username, password, position);
				listemployee.add(ee);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return listemployee;
	}

	public void setListemployee(Vector listemployee) {
		this.listemployee = listemployee;
	}
	
public void insert_employee(Employee cus) {
		String sql = "Insert into Employee values(" + cus.getID()
				+ ",'" + cus.getFirstname()+ "','" +cus.getLastname() + "','"
				+ cus.getUsername() + "','" + cus.getPassword()+ "',"
				+ cus.getPosition()+")";
		 connectDataBase.query_update(sql);
	}
}


